
//发送更改
function submit() {
    $.ajax({
        type: "post",
        url: "/blog/update",
        contentType: "application/json",
        data: JSON.stringify({
            id: $("#blogId").val(),
            title: $("#title").val(),
            content: $("#content").val()
        }),
        success: function (ret){
            if(ret.code==200 && ret.data){
                location.href = "blog_detail.html?blogId="+$("#blogId").val();
            }else {
                alert("博客更新失败，"+ret.errMge);
            }
        }
    });
}

//先获取博客详情
function getBlogInfo() {
    $.ajax({
        type: "get",
        url: "/blog/getblogdetail"+location.search,
        success: function (ret) {
            if (ret.code != 200 || ret.data == null) {
                if (ret.code == -1) {
                    alert(ret.errMge);
                }
                return;
            }

            $("#blogId").val(ret.data.id);
            $("#title").val(ret.data.title);
            // $("#content").val(result.data.content);
            editormd("editor", {
                width: "100%",
                height: "550px",
                path: "blog-editormd/lib/",
                onload: function () {
                    this.watch();
                    this.setMarkdown(ret.data.content);
                }
            });
        }
    });
}

getBlogInfo();